import {Injectable} from '@angular/core';
import {environment} from "../../../../../environments/environment";
import {HttpUtilService} from "../../../../services/http/http-util.service";
import {Observable} from "rxjs";
import {BarnProduct} from "../product/entity/barn-product";
import {BarnProject} from "../project/entity/barn-project";

@Injectable({
  providedIn: 'root'
})
export class ProjectProductService {

  private prefix = environment.serverName.pp + "/project-product/"

  constructor(private http: HttpUtilService) {
  }

  projectAddProducts(projectId: string, productIds: string[], handleError = true) {
    return this.http.post(this.prefix + "projectAddProducts", {projectId, productIds}, handleError)
  }

  getProductByProject(projectId: string, handleError = true): Observable<BarnProduct[]> {
    return this.http.get(this.prefix + "getProductByProject/" + projectId, handleError)
  }


  getProjectByProduct(productId: string, handleError = true): Observable<BarnProject[]> {
    return this.http.get(this.prefix + "getProjectByProduct/" + productId, handleError)
  }

  delete(projectId: string, productId: string, handleError = true) {
    return this.http.post(this.prefix + "delete", {projectId, productId}, handleError)
  }
}
